package com.zkyc.framework.website.controller;

import com.zkyc.framework.common.Enum.LogType;
import com.zkyc.framework.common.annotation.Log;
import com.zkyc.framework.common.annotation.Timing;
import com.zkyc.framework.common.exception.ResultCode;
import com.zkyc.framework.common.pojo.Center;
import com.zkyc.framework.common.vo.ResultVO;
import com.zkyc.framework.website.service.CenterService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Center)表控制层
 *
 * @author libingchuan
 * @since 2022-05-25 19:21:46
 */
@RestController
@RequestMapping("center")
public class CenterController {
    /**
     * 服务对象
     */
    @Resource
    private CenterService centerService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/query/{id}")
    @Timing
    public ResultVO queryById(@PathVariable("id") Integer id) {
        Center center = centerService.queryById(id);
        if (center == null) {
            return ResultVO.fail(ResultCode.SERVE_ERROR);
        }
        return ResultVO.data(center);
    }

    /**
     * 新增数据
     *
     * @param center 实体
     * @return 新增结果
     */
    @PostMapping("save")
    @Log(type = LogType.增加下级)
    public ResultVO add(@RequestBody Center center) {
        return centerService.insert(center);
    }

    /**
     * 编辑数据
     *
     * @param center 实体
     * @return 编辑结果
     */
    @PostMapping("edit")
    @Log(type = LogType.保存中心)
    public ResultVO edit(@RequestBody Center center) {
        return centerService.update(center);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("delete")
    @Log(type = LogType.删除中心)
    public ResultVO deleteById(Integer id) {
        return centerService.deleteById(id);
    }

    @GetMapping("addPi")
    public ResultVO addPi(String userCode) {
        return centerService.addPi(userCode);
    }


    @GetMapping("getCenterInfo")
    public ResultVO getCenterInfo(@RequestParam("id") Integer  id, Integer isVerified)  {
        return centerService.getCenterInfo(id,isVerified);
    }


    @GetMapping("deletePi")
    public ResultVO deletePi(Integer id, String userCode) {
        return centerService.deletePi(id, userCode);
    }

    @GetMapping("submit")
    public ResultVO submit(Integer id, Integer centerId) {
        return centerService.submit(id, centerId);
    }

}

